import os
import platform

os.chdir(os.path.dirname(os.path.realpath(__file__)))


from common import *
from client import *
from core import *
ROUTE_SUFFIX_MASK = getMask()
GNB_NODEID=''
hosts = HOST_LIST.split(',')
routes = []

for host in hosts:
    routes.append('%s|%s|%s'%(IPtoNodeId(host),host,ROUTE_SUFFIX_MASK))
    # print(GNB_IP,host)
    if GNB_IP == host:
        GNB_NODEID=IPtoNodeId(host)
    # print(IPtoNodeId(host), ROUTE_SUFFIX_MASK)

routes=','.join(routes)

# "1002|172.27.0.2|255.255.0.0,1003|172.27.0.3"
system=platform.system()
if (system=='Windows' or system.find('NT')>0) and GNB_COMMAND.find('.exe')<1:
    GNB_COMMAND=GNB_COMMAND+'.exe'

print(system,GNB_COMMAND.find('.exe'))
command=f'{GNB_COMMAND} -n {GNB_NODEID} -a {GNB_IP}  -I "{GNB_SERVER}" --multi-socket=on -p {GNB_PASSWORD} -r "{routes}"'
print(command)
os.system(command)
# print(routes)
# print(HOST_LIST)
